#!/bin/bash

f() {
    echo "in function, before changing, a == $a"
    a=$((a+1))
    echo "in function, after changing, a == $a"
}

f2() {
    local a=$a
    echo "in function, before changing, a == $a"
    a=$((a+1))
    echo "in function, after changing, a == $a"
}

a=101
echo "before calling function, out of function, a == $a"
f2
echo "after calling function, out of function, a == $a"
